import java.util.Scanner;

public class One {
    public static void main(String[] args) {
        Scanner in= new Scanner(System.in);
        int t=in.nextInt();
        while (t--!=0){
            int n=in.nextInt();
            int k=in.nextInt();
            char[] s=in.next().toCharArray();
             int ret=0;
            for (int i = 0; i < s.length; i++) {
                if (s[i]=='L')
                    ret-=1;
                else {
                    if (i-1>=0&&i-2>=0&&s[i-1]=='W'&&s[i-2]=='W'){
                        ret+=k;
                    }else {
                        ret+=1;
                    }
                }
            }
            System.out.println(ret);
        }
    }
}
